package com.javaeedev.junit;

import com.opensymphony.webwork.ServletActionContext;
import com.opensymphony.xwork.Action;

public class SignOnWebWork2Action implements Action {

    private String username;
    private String password;

    private Service service;

    public void setService(Service service) {
        this.service = service;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String execute() throws Exception {
        try {
            service.signon(username, password);
            ServletActionContext.getRequest().getSession().setAttribute("signon", username);
            return SUCCESS;
        }
        catch(RuntimeException e) {
            return ERROR;
        }
    }

}
